#include "stdafx.h"
#include "SnakeList.h"


SnakeList::SnakeList(SnakeBody *head)
{
	this->p_Lhead = this->p_Lend = head;
	head->lest = nullptr;
	head->next = nullptr;
	this->snakeLeght = 1;
}


SnakeList::~SnakeList()
{
}

void SnakeList::addSnake(SnakeBody * body)
{
	if (p_Lhead == nullptr)
	{
		p_Lhead = body;
		p_Lend = p_Lhead;
		p_Lend->next = nullptr;
		p_Lend->lest = nullptr;
		this->snakeLeght += 1;
	}
	else
	{
		body->lest = p_Lend;
		p_Lend->next = body;
		p_Lend = p_Lend->next;
		p_Lend->next = nullptr;
	}
	this->snakeLeght += 1;
}

void SnakeList::clearList()
{
	SnakeBody*p_move = p_Lhead;
	SnakeBody* p_delete;
	while (p_move!=nullptr)
	{
		p_delete = p_move;
		p_move = p_move->next;
		delete p_delete;
	}
	this->snakeLeght = 0;
	p_Lend = p_Lhead=nullptr;
}

SnakeBody * SnakeList::getHead()const
{
	return this->p_Lhead;
}

SnakeBody * SnakeList::getEnd() const
{
	return p_Lend;
}
